package com.dbManage.page.record;

import com.alibaba.fastjson.JSON;
import com.dbManage.dao.RecordDao;
import com.dbManage.entity.Message;
import com.dbManage.entity.Note;
import com.dbManage.entity.NoteRecord;
import com.dbManage.page.note.NoteService;
import com.dbManage.tools.IpTool;
import com.wsse.common.tool.Console;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class RecordController {

    @Resource
    RecordService recordService;
    @Resource
    RecordDao recordDao;

    @RequestMapping("/record")
    @ResponseBody
    public Message saveRecord(HttpServletRequest request , int id){
        String ip = IpTool.getIpAddr(request);
        Note note = recordDao.findNoteById(id);
        recordService.insertNoteRecord(note,ip);
        return new Message(Message.STATUS_SUCCESS,"记录成功");
    }

    @RequestMapping("/noteRecordView")
    public String noteRecordView(Model model ,int id){
        List<NoteRecord> list=recordDao.findNoteRecordById(id);
        String listStr=JSON.toJSONString(list);
        model.addAttribute("listStr",listStr);
        return "record";
    }

}
